package com.pgytesting.secondhandcar.controller.admin;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.pgytesting.secondhandcar.model.OrderName;
import com.pgytesting.secondhandcar.model.Power;
import com.pgytesting.secondhandcar.service.OrderNameService;
import com.pgytesting.secondhandcar.vo.Parameters;
import com.pgytesting.secondhandcar.vo.ResponseMessage;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@RestController
@RequestMapping("/admin/loanManagement")
public class LoanManagementController {
	
	@Autowired
	private OrderNameService orderNameService;
	
	
	/**
	 * 获取贷款信息材料列表
	 * @param orderName
	 * @return
	 */
	@RequestMapping(value = "/getLoanOrderList",method = RequestMethod.POST)
	public ResponseMessage getListObj() {
		try {
			OrderName orderName = new OrderName();
			orderName.setOrderStatus(Parameters.ORDER_23001);
			orderName.setStatus(0);
			return ResponseMessage.successResponse(orderNameService.queryAll(orderName));			
		} catch (Exception e) {
			e.printStackTrace();
			return ResponseMessage.errorResponse("获取贷款列表出现异常");
		}
	}
	
	/**
	 * 贷款资料审核通过
	 * @param orderName
	 * @return
	 */
	@RequestMapping(value = "/loanExamineAdopt",method = RequestMethod.POST)
	public ResponseMessage loanExamineAdopt(@RequestBody OrderName orderName) {
		try {
			if(orderName.getId() == null) {
				return ResponseMessage.errorResponse("订单id不能为空");
			}
			orderNameService.applyLoanExamine(orderName.getId(), Parameters.ORDER_23002, 0);
			return ResponseMessage.successResponse("审核通过成功");			
		} catch (Exception e) {
			e.printStackTrace();
			return ResponseMessage.errorResponse("审核通过出现异常");
		}
	}
	
	/**
	 * 贷款审核驳回
	 * @param orderName
	 * @return
	 */
	@RequestMapping(value = "/loanExamineRebut",method = RequestMethod.POST)
	public ResponseMessage loanExamineRebut(@RequestBody OrderName orderName) {
		try {
			if(orderName.getId() == null) {
				return ResponseMessage.errorResponse("订单id不能为空");
			}
			orderNameService.applyLoanExamine(orderName.getId(), Parameters.ORDER_23003, 2);
			return ResponseMessage.successResponse("审核驳回成功");
		} catch (Exception e) {
			e.printStackTrace();
			return ResponseMessage.errorResponse("审核驳回出现异常");
		}
	}
	
	/**
	 * 贷款审核拒绝
	 * @param orderName
	 * @return
	 */
	@RequestMapping(value = "/loanExamineRefuse",method = RequestMethod.POST)
	public ResponseMessage loanExamineRefuse(@RequestBody OrderName orderName) {
		try {
			if(orderName.getId() == null) {
				return ResponseMessage.errorResponse("订单id不能为空");
			}
			orderNameService.applyLoanExamine(orderName.getId(), Parameters.ORDER_23004, 1);
			return ResponseMessage.successResponse("审核拒绝成功");			
		} catch (Exception e) {
			e.printStackTrace();
			return ResponseMessage.errorResponse("审核拒绝出现异常");
		}
	}
	
}
